import request from '@/utils/request'
import type {Doctor, DoctorUpdateRequest, DoctorAddRequest} from '@/types/doctor'
import type {CheckTask} from '@/types/checkTask'
import type {CheckType} from '@/types/checkType'

// 定义查询参数类型
export interface DoctorQueryParams {
    DoctorName?: string;  // 子女姓名（模糊查询）
    phone?: string;      // 电话号码（模糊查询）
    communityId?: number; // 社区ID（精确匹配）
}

export interface DoctorAndElderAndDate {
    doctorId: number,
    date?: string,
    elderName?: string
}

// 获取所有医生
export function getAllDoctors(params?: DoctorQueryParams) {
    return request<Doctor[]>({
        url: '/doctor/findAll',
        method: 'get',
        params
    })
}

// 添加医生
export function addDoctor(data: DoctorAddRequest) {
    return request<boolean>({
        url: '/doctor/register',
        method: 'post',
        data
    })
}

// 删除医生
export function deleteDoctor(data: { id: number }) {
    return request<boolean>({
        url: '/doctor/delDoctor',
        method: 'delete',
        data
    })
}

// 更新医生信息
export function updateDoctor(data: DoctorUpdateRequest) {
    return request<Doctor>({
        url: '/doctor/updateDoctor',
        method: 'post',
        data
    })
}

// 获取医生检查任务列表
export function getDoctorCheckTasks(params: DoctorAndElderAndDate) {
    return request<CheckTask[]>({
        url: '/doctor/getDoctorCheckTask',
        method: 'get',
        params
    })
}

// 更新检查任务状态
export function updateDoctorCheckTask(data: CheckTask) {
    return request<boolean>({
        url: '/doctor/updateDoctorCheckTask',
        method: 'post',
        data
    })
}

// 删除检查任务
export function deleteDoctorCheckTask(id: number) {
    return request<boolean>({
        url: '/doctor/delDoctorCheckTask',
        method: 'delete',
        params: {id}
    })
}

// 添加检查任务
export function addDoctorCheckTask(data: CheckTask) {
    return request<boolean>({
        url: '/elder/addCheckTask',
        method: 'post',
        data
    })
}

// 获取检查类型列表
export function getCheckTypes() {
    return request<CheckType[]>({
        url: '/community/getCheckType',
        method: 'get'
    })
}

